package com.wwm.makerandroid.makerandroid.View.Adapter;

import static com.wwm.makerandroid.makerandroid.Utils.ParseUtil.getStateString;
import static com.wwm.makerandroid.makerandroid.Utils.ParseUtil.getTypeString;

import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lipiao.makerandroid.R;
import com.wwm.makerandroid.makerandroid.Bean.RespondBean.RecordBean;
import com.wwm.makerandroid.makerandroid.Bean.RespondBean.TempBean;
import com.wwm.makerandroid.makerandroid.Bean.ViewBean.ApplyBean;
import com.wwm.makerandroid.makerandroid.Utils.HttpUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


//请假申请适配器（top）——recycleView+cardView
public class ApplyRecordAdapter extends RecyclerView.Adapter<ApplyRecordAdapter.ContactViewHolder> {


    View applyView;
    //MyAdapter的成员变量contactInfoList, 这里被用作数据的来源
    private List<RecordBean.DataBean> recordBeanList;

    //构造函数
    public ApplyRecordAdapter(List<RecordBean.DataBean> recordBeanList) {
        this.recordBeanList = recordBeanList;
    }


    //重写3个抽象方法
    @NonNull
    @Override
    public ApplyRecordAdapter.ContactViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View itemView = LayoutInflater.from(viewGroup.getContext()).
                inflate(R.layout.record_card_item, viewGroup, false);
        return new ContactViewHolder(itemView);

    }

    //    fixme 预览信息不显示  点击事件正常  fix 预览信息不知道为什么 字体颜色被改为白色了 和背景相同看不见
    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull ApplyRecordAdapter.ContactViewHolder contactViewHolder, int i) {
//        citybeanList中包含的都是citybean类的对象
//        通过其get()方法可以获得其中的对象
        RecordBean.DataBean recordBean = recordBeanList.get(i);
        contactViewHolder.state.setText(getStateString(recordBean.getState()));
        contactViewHolder.applyType.setText(getTypeString(recordBean.getType()));
        //未通过审核的就将其备注信息颜色设为红色
        if (recordBean.getState() == 3) {
            contactViewHolder.remark.setTextColor(-65536);
        } else {
            contactViewHolder.remark.setTextColor(-16777216);
        }
        contactViewHolder.detail.setText(recordBean.getReason());
        contactViewHolder.remark.setText(recordBean.getRemark());
        contactViewHolder.time.setText("从" + recordBean.getOutDate().substring(0, 16) + " 到 " + recordBean.getExpectedReturnDate().substring(0, 16));

        //todo
//        点击item 不同地方跳转到对应页面
    }

    @Override
    public int getItemCount() {
        return recordBeanList.size();
    }

    //重点：该泛型必须是 自定义的适配器(如MyAdapter).ViewHolder
    class ContactViewHolder extends RecyclerView.ViewHolder {
        //create the viewHolder class
//        protected CardView type;
        protected TextView applyType;
        protected TextView detail;
        protected TextView state;
        protected TextView time;
        protected TextView remark;
        protected CardView apply;


        public ContactViewHolder(View itemView) {
            super(itemView);
            applyType = itemView.findViewById(R.id.tv_apply_type);
            detail = itemView.findViewById(R.id.tv_detail);
            state = itemView.findViewById(R.id.tv_apply_state);
            time = itemView.findViewById(R.id.tv_top_article_time);
            remark = itemView.findViewById(R.id.tv_remark);
            apply = itemView.findViewById(R.id.cv_top_record_card);

        }

    }

//    //有关监听（外部调用）
//    public void setOnItemClickListener(ApplyRecordAdapter.OnItemClickListener onItemClickListener) {
//        this.onItemClickListener = onItemClickListener;
//    }
//
//    private OnItemClickListener onItemClickListener= (view, position) -> System.out.println("qweqweqweqwe点击");
//
//    /**
//     * 自定义监听回调接口，RecyclerView 的 单击事件
//     */
//    public interface OnItemClickListener {
//        void onItemClick(View view, int position);
//    }

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            System.out.println("qweqwe点击");
        }
    };


}//adapter.class